package com.linkzd.iot.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.linkzd.iot.domain.DeviceInfo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.linkzd.common.annotation.Log;
import com.linkzd.common.core.controller.BaseController;
import com.linkzd.common.core.domain.AjaxResult;
import com.linkzd.common.enums.BusinessType;
import com.linkzd.iot.domain.DeviceDataLog;
import com.linkzd.iot.service.IDeviceDataLogService;
import com.linkzd.common.utils.poi.ExcelUtil;
import com.linkzd.common.core.page.TableDataInfo;

/**
 * 数据历史记录Controller
 * 
 * @author ruoyi
 * @date 2024-05-28
 */
@RestController
@RequestMapping("/iot/deviceDataLog")
public class DeviceDataLogController extends BaseController
{
    @Autowired
    private IDeviceDataLogService deviceDataLogService;

    /**
     * 查询数据历史记录列表
     */
    @PreAuthorize("@ss.hasPermi('iot:deviceDataLog:list')")
    @GetMapping("/list")
    public TableDataInfo list(DeviceDataLog deviceDataLog)
    {
        startPage();
        List<DeviceDataLog> list = deviceDataLogService.selectDeviceDataLogList(deviceDataLog);
        return getDataTable(list);
    }

    /**
     * 导出数据历史记录列表
     */
    @PreAuthorize("@ss.hasPermi('iot:deviceDataLog:export')")
    @Log(title = "数据历史记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DeviceDataLog deviceDataLog)
    {
        List<DeviceDataLog> list = deviceDataLogService.selectDeviceDataLogList(deviceDataLog);
        ExcelUtil<DeviceDataLog> util = new ExcelUtil<DeviceDataLog>(DeviceDataLog.class);
        util.exportExcel(response, list, "数据历史记录数据");
    }

    /**
     * 获取数据历史记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('iot:deviceDataLog:query')")
    @GetMapping(value = "/{dataId}")
    public AjaxResult getInfo(@PathVariable("dataId") Long dataId)
    {
        return success(deviceDataLogService.selectDeviceDataLogByDataId(dataId));
    }

    /**
     * 新增数据历史记录
     */
    @PreAuthorize("@ss.hasPermi('iot:deviceDataLog:add')")
    @Log(title = "数据历史记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DeviceInfo deviceInfo)
    {
        return toAjax(deviceDataLogService.insertDeviceDataLog(deviceInfo));
    }

    /**
     * 修改数据历史记录
     */
    @PreAuthorize("@ss.hasPermi('iot:deviceDataLog:edit')")
    @Log(title = "数据历史记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DeviceDataLog deviceDataLog)
    {
        return toAjax(deviceDataLogService.updateDeviceDataLog(deviceDataLog));
    }

    /**
     * 删除数据历史记录
     */
    @PreAuthorize("@ss.hasPermi('iot:deviceDataLog:remove')")
    @Log(title = "数据历史记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{dataIds}")
    public AjaxResult remove(@PathVariable Long[] dataIds)
    {
        return toAjax(deviceDataLogService.deleteDeviceDataLogByDataIds(dataIds));
    }
}
